﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Logic.ClarizenSvc;
using Logic.ClarizenObjects;
using Logic;

namespace ClarizenGadget.Controllers
{
    public class EmailsController : Controller
    {
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Task(string taskID)
        {
            var eq = new EntityQuery
            {
                Fields = BaseObject.GetFields(typeof(Email)),
                TypeName = "Email",
                Where = new Compare { LeftExpression = new FieldExpression { FieldName = "AttachedTo" }, Operator = Operator.Equal, RightExpression = new ConstantExpression { Value = new EntityId { TypeName = "WorkItem", Value = taskID } } }
            };

            var emails = new QueryComponent().ExecuteQuery(eq);

            return View(emails.Select(e => BaseObject.Intitialize<Email>(e)));
        }

    }
}
